import Vue from 'vue'
import VueRouter from 'vue-router'
// 模块之间需要引入才能使用，引入仓库
// import store from '@/store'
// 引入组件
import Layout from '@/views/layout'
import Login from '@/views/login'
import Dashboard from '@/views/dashboard'
//
import BaseInfo from './module/baseinfo'
import Business from './module/business'
import Chuku from './module/chuku'
import Ruku from './module/ruku'
import Kunei from './module/kunei'
// import ManageStorage from './modules/manage-storage'
Vue.use(VueRouter)
const constantRoutes = [
  {
    path: '/',
    component: Login
  },
  {
    path: '/dashboard',
    component: Layout,
    children: [
      { path: '', component: Dashboard }
    ]
  }
]
// const asyncRoutes = [BaseInfo, ManageBusiness, ManageStorage]
const asyncRoutes = [BaseInfo, Business, Chuku, Ruku, Kunei]

const router = new VueRouter({
  routes: [...constantRoutes, ...asyncRoutes, { path: '*', redirect: '/404' }]
})
// const whiteList = ['/login']
// 路由前置守卫，每次进入一个路由地址，都会触发这个函数
// router.beforeEach((to, from, next) => {
//   const token = store.state.user.token
//   if (token) {
//     next()
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login')
//     }
//   }
// })

export default router
